package 多线程案例;

import java.util.concurrent.Semaphore;

//信号量
public class Demo_9 {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(10);
        semaphore.acquire(3);
        System.out.println("申请");
        semaphore.acquire(2);
        System.out.println("申请");
        //超出限制，会陷入阻塞
        semaphore.acquire(9);
        System.out.println("申请");
        semaphore.release(10);
        System.out.println("释放");
        //释放资源不会陷入阻塞
        semaphore.release(19);
        System.out.println("释放");
    }
}
